{extend name="public/base" /}
{block name='head'}
<meta charset="utf-8">
<title>{$i.Title}</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="{$i.Desc|default='资源共享平台,孙武'|process_resource_desc_of_htmldesc}">
<meta name="description" content="{$i.Desc|default='资源共享平台,孙武'|process_resource_desc_of_htmldesc}">
<link rel="stylesheet" href="__LAYUI__/css/layui.css">
<link rel="stylesheet" href="__CSS__/global.css">
<link rel="stylesheet" href="__CSS__/common.css">
<script src="__LAYUI__/layui.js"></script>
{/block}
{block name='body'}
<div class="layui-container">
    <div class="layui-row ">
        <div class="layui-col-md12 content detail">
            <div class="fly-panel detail-box">
                <h1>{$i.Title}</h1>
                <div class="fly-detail-info">
                    <!-- <span class="layui-badge">审核中</span> -->
                    <span class="layui-badge layui-bg-green fly-detail-column"
                          title="资源分类"><i class="layui-icon">&#xe63c;</i>{$i['category']['Name']}</span>

                    <!-- <span class="layui-badge" style="background-color: #5FB878;">已结</span> -->

                    <span class="layui-badge layui-bg-green" title="分享时间"><i class="layui-icon">&#xe637;</i> {$i.CreateTime}</span>
                    <span title="所需金币" class="layui-badge layui-bg-green">

                        <!--<img src="__IMG__/goldIcon.png" class="sw-money-icon">-->
                        <i class="layui-icon">&#xe659;</i>
                        {$i.Price}</span>

                    <div class="fly-admin-box" id="tools-icon">

                        <!--<span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="1">删除</span>-->
                        <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="0" style="background-color:#ccc;">取消置顶</span> -->

                        <!--收藏-->
                        <span class="layui-btn layui-btn-xs jie-admin layui-hide" id="start"
                              api="{:url('user/resDetailToolsApi')}?guid={$i.PK_ResourceGuid}&type=start">
                            <i class="layui-icon">&#xe600;</i>收藏
                        </span>
                        <!--已收藏-->
                        <span class="layui-btn layui-btn-xs jie-admin layui-hide" id="unstart"
                              api="{:url('user/resDetailToolsApi')}?guid={$i.PK_ResourceGuid}&type=unstart">
                            <i class="layui-icon">&#xe658;</i>已收藏
                        </span>
                        <!--顶-->
                        <span class="layui-btn layui-btn-xs jie-admin" id="top"
                              api="{:url('user/resDetailToolsApi')}?guid={$i.PK_ResourceGuid}&type=top">
                            <i class="layui-icon">&#xe6c6;</i>顶一下
                        </span>
                        <!--鄙视-->
                        <span class="layui-btn layui-btn-xs jie-admin" id="untop"
                              api="{:url('user/resDetailToolsApi')}?guid={$i.PK_ResourceGuid}&type=untop">
                            <i class="layui-icon">&#xe6c5;</i>踩一下
                        </span>
                        <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="0" style="background-color:#ccc;">取消加精</span> -->
                    </div>
                    <span class="fly-list-nums">
            <span title="顶量"><img src="__IMG__/top.png" class="sw-dotop-icon"><span
                    id="res-tops">{$i.Tops}</span></span>
            <a href="#comment"><i class="iconfont" title="评论量">&#xe60c;</i>{$i['rescomment']|comment_array_to_count}</a>
            <i class="iconfont" title="浏览量">&#xe60b;</i> {$i.PageView}
          </span>
                </div>

                <div class="detail-about">
                    <a class="fly-avatar" href="{:url('user/userDetail')}?guid={$i['user']['PK_UserGuid']}"> <img
                            src="__PUBLIC__/{$i['user']['Cover']}" alt="资源"> </a>
                    <div class="fly-detail-user">
                        <a href="{:url('user/userDetail')}?guid={$i['user']['PK_UserGuid']}" class="fly-link">
                            <cite>{$i['user']['Name']}</cite> <i
                                class="layui-badge fly-badge-vip">{$i['user']['Level']}</i> </a>
                        <span>{$i['user']['CreateTime']}</span>
                    </div>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
                        <span title="所需金币">
                            <img src="__IMG__/goldIcon.png" class="sw-money-icon">
                            {$i['user']['Gold']} </span>
                        <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a
                                href="{:url('home/user/modifyShare')}?guid={$i.PK_ResourceGuid}">编辑</a></span>
                    </div>
                </div>

                <div class="detail-body photos sw-desc-content">
                    {$i.Desc}
                </div>

                <hr>

                <fieldset class="layui-elem-field sw-download-box">
                    <legend>附件</legend>
                    <div class="layui-field-box" id="download-content">

                    </div>

                </fieldset>
            </div>
            <div class="fly-panel detail-box" id="flyReply">
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>评论</legend>
                </fieldset>

                <ul class="jieda" id="sw-comment">
                    {if condition='count($i.rescomment)>0'} {foreach name='i.rescomment' item='item'}
                    <li data-id="111" class="jieda-daan">
                        <a name="item-1111111111"></a>
                        <div class="detail-about detail-about-reply">
                            <a class="fly-avatar" href="{:url('user/userDetail')}?guid={$item['user']['PK_UserGuid']}">
                                <img src="__PUBLIC__/{$item['user']['Cover']}" alt=" "> </a>
                            <div class="fly-detail-user">
                                <a href="{:url('user/userDetail')}?guid={$item['user']['PK_UserGuid']}"
                                   class="fly-link"> <cite>{$item['user']['Name']}</cite> <i
                                        class="layui-badge fly-badge-vip">{$item['user']['Level']}</i> </a>

                                <span>(~__~)</span>
                            </div>

                            <div class="detail-hits">
                                <span>{$item.CreateTime}</span>
                            </div>

                        </div>
                        <div class="detail-body jieda-body photos ">
                            <p class="sw-comment-item">{$item.comment}</p>
                        </div>
                        <div class="jieda-reply layui-hide">
                          <span class="jieda-zan" type="zan">
                            <i class="iconfont icon-zan"></i>
                            <em>66</em>
                          </span> <span type="reply">
                            <i class="iconfont icon-svgmoban53"></i>
                            回复
                          </span>
                            <div class="jieda-admin">
                                <span type="edit">编辑</span> <span type="del">删除</span>
                            </div>
                        </div>
                    </li>
                    {/foreach} {else /}
                    <!-- 无数据时 -->
                    <li class="fly-none">暂无评论</li>
                    {/if}
                </ul>

                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item layui-form-text">
                        <a></a>
                        <div class="layui-input-block">
                            <textarea id="L_content" name="comment" required lay-verify="required" placeholder="请输入内容"
                                      class="layui-textarea fly-editor" style="height: 150px;"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <input type="hidden" name="resguid" value="{$i.PK_ResourceGuid}">
                        <button class="layui-btn" lay-filter="replay" lay-submit>提交回复</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{/block}{block name='defaultScript'}
<script>

    layui.config({
        version: "1.0.0"
        , base: '__JS__/' //这里实际使用时，建议改成绝对路径
    }).extend({
        fly: 'index'
    }).use(['form', 'jquery', 'fly', 'face', 'jquery'], function ()
    {

        let form = layui.form, $ = layui.jquery, fly = layui.fly;

        let layer = layui.layer;
        $('.fly-search').on('click', function ()
        {
            let api = "{:url('index/search')}";
            layer.open({
                type: 1
                , title: false
                , closeBtn: false
                //,shade: [0.1, '#fff']
                , shadeClose: true
                , maxWidth: 10000
                , skin: 'fly-layer-search'
                , content: [`<form action="${api}">`
                    , '<input autocomplete="off" placeholder="搜索内容，回车跳转" type="text" name="q">'
                    , '</form>'].join('')
                , success: function (layero)
                {
                    let input = layero.find('input');
                    input.focus();

                    layero.find('form').submit(function ()
                    {
                        let val = input.val();
//                        if(val.replace(/\s/g, '') === ''){
//                            return false;
//                        }
                        input.val(input.val());
                    });
                }
            })
        });
        /**
         * 评论
         */
        form.on('submit(replay)', function (data)
        {
            let replayData = data.field;
            console.log(replayData);
            $.post("{:url('user/rescomment')}", replayData, function (res)
            {
                if (res.errno === -2) return layer.msg('请登录后重试');
                if (res.errno === 0)
                {
                    layer.msg(res.errmsg);
                    setInterval(function ()
                    {
                        location.reload();
                    }, 2000);
                }
                if (res.errno === -1) return layer.msg(res.errmsg);
                if (res.errno === 1) return layer.msg(res.errmsg);
                return false;
            });
            return false;
        });

        $('#tools-icon span').click(function ()
        {
            let api = $(this).attr('api');
            let patt = /&type=(.*)/;
            let pattRes = patt.exec(api);
            let type = pattRes[1];
            $.get(api, function (res)
            {
                layer.msg(res.errmsg);
                if (res.errno === 0)
                {
                    if (type === 'start' || type === 'unstart')
                    {
                        startectionStatus();
                    }
                    if (type === 'top')
                    {
                        let obj = $('#res-tops');
                        let tops = obj.html();
                        tops++;
                        obj.html(tops);
                    }
                    if (type === 'untop')
                    {
                        let obj = $('#res-tops');
                        let tops = obj.html();
                        tops--;
                        obj.html(tops);
                    }
                }
            })
        });

        //获取资源状态[显示可用或不可用]
        function startectionStatus()
        {
            $.get("{:url('user/resCollStatus')}?guid={$i.PK_ResourceGuid}", function (res)
            {
                if (res.errno === -2)
                {
                    startHide();
                    $('#start').removeClass('layui-hide');
                }
                if (res.errno === 0)
                {
                    if (res.data === '可用')
                    {
                        startHide();
                        $('#unstart').removeClass('layui-hide');
                    } else
                    {
                        startHide();
                        $('#start').removeClass('layui-hide');
                    }
                }
            });
        }

        startectionStatus();

        /**
         * 隐藏收藏
         * */
        function startHide()
        {
            $('#start').addClass('layui-hide');
            $('#unstart').addClass('layui-hide');
        }

        /**
         * 顶一下
         */
        $('#sw-tops').click(function ()
        {
//            console.log(this);
            let guid = $(this).attr('guid');
            $.post("{:url('user/tops')}", {guid: guid}, function (res)
            {
                if (res.errno === -2) return layer.msg('请登录后重试');
                if (res.errno === 0)
                {
                    layer.msg(res.errmsg);
                    setInterval(function ()
                    {
                        location.reload();
                    }, 2000);
                }
                if (res.errno === -1) return layer.msg(res.errmsg);
                if (res.errno === 1) return layer.msg(res.errmsg);
                return false;
            })
        });
        /**
         * 踩一下
         */
        $('#sw-down').click(function ()
        {
            let guid = $(this).attr('guid');
            $.post("{:url('user/tops')}", {guid: guid}, function (res)
            {
                if (res.errno === -2) return layer.msg('请登录后重试');
                if (res.errno === 0)
                {
                    layer.msg(res.errmsg);
                    setInterval(function ()
                    {
                        location.reload();
                    }, 2000);
                }
                if (res.errno === -1) return layer.msg(res.errmsg);
                if (res.errno === 1) return layer.msg(res.errmsg);
                return false;
            })
        });

        /**
         * 评论转义
         */
        $("#sw-comment li").each(function ()
        {
            let othis = $(this).find('.sw-comment-item');
            let html = othis.html();
            othis.html(fly.content(html));
//
        })

        /**
         * 详细详细转义
         */
        {
            let obj = $('.sw-desc-content');
            let html = obj.html();
            obj.html(fly.content(html));
        }





        //获取附件
        function getAccessory()
        {
            $.get("{:url('user/resIsPaidApi')}?res_guid={$i.PK_ResourceGuid}", function (res)
            {

                if (res.errno === 0)
                {
                    let type = res.data.type;
                    let type_value = res.data.type_value;

                    if (type_value =='') return $('#download-content').html(`糟糕,作者没有上传或分享任何附件`);

                    switch (type)
                    {
                        case "网盘资源":
                        {

                            let arr = type_value.split('-');
                            let pantpl;
                            if (arr[1].length > 1)
                            {
                                pantpl = ` 网盘地址:<a href="${arr[0]}">${arr[0]}</a>
                        <span>提取密码: <span>${arr[1]}</span></span>`;
                            } else
                            {
                                pantpl = ` 网盘地址:<a href="${arr[0]}">${arr[0]}</a>
                        <span>提取密码: <span>公开</span></span>`;
                            }
                            pushDownloadContent(pantpl);

                        }
                            break;
                        case "实体资源":
                        {
                            $('#download-content').html(`附件下载:<a href="${type_value}">下载附件</a>`);
                        }
                            break;
                        case "URL资源":
                        {
                            if (type_value.indexOf('://') < 0) return pushDownloadEmptyContent();
                            $('#download-content').html(`参考网站:<a href="${type_value}">{$i.type_value}</a>`);
                        }
                            break;
                        case "文本资源":
                        {
                            pushDownloadEmptyContent();
                        }
                            ;
                            break;
                        default:
                        {
                            return pushDownloadEmptyContent();
                        }
                            break;
                    }
                }
                if (res.errno === 5)
                {
                    pushDownloadContent(`<a  id="payres" href="javascript:void(0);">购买</a> 后才能查看附件`);
                }
                if (res.errno === -2)
                {
                    pushDownloadContent(`<a href="{:url('login/login')}">登录</a> 后才能查看附件`);
                }
            });
        }

        //获取附件
        getAccessory();



        function pushDownloadContent(content)
        {
            $('#download-content').html(content);
        }


        function pushDownloadEmptyContent()
        {
            pushDownloadContent('糟糕,作者没有上传或分享任何附件');
        }


        $('#download-content').on('click', function ()
        {
            let html = $(this).html();
            let index = html.indexOf("购买")
            if (index > 0) return payres();
        });

        /**
         * 购买附件
         */
        function payres()
        {
            $.get("{:url('user/resPaidApi')}?res_guid={$i.PK_ResourceGuid}", function (res)
            {
                if(res.errno===0){
                    layer.msg('购买成功');
                    getAccessory();

                }else{
                    layer.msg(res.errmsg);
                    getAccessory();
                }
            })
        }

    });

</script>
{/block}